package com.lineage.server.command.executor;

import com.lineage.server.datatables.SkillsTable;
import com.lineage.server.datatables.lock.CharSkillReading;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_AddSkill;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Skills;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1AddSkill implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1AddSkill.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1AddSkill();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      int cnt = 0;
      String skill_name = "";
      int skill_id = 0;
      int object_id = pc.getId();
      pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(object_id, 227));
      if (pc.isCrown()) {
        pc.sendPackets((ServerBasePacket)new S_AddSkill(pc, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 
              0, 0, 0, 0, 0, 0, 0));
        cnt = 1;
        while (cnt <= 16) {
          L1Skills l1skills = SkillsTable.get().getTemplate(cnt);
          skill_name = l1skills.getName();
          skill_id = l1skills.getSkillId();
          CharSkillReading.get().spellMastery(object_id, skill_id, skill_name, 0, 0);
          cnt++;
        } 
        cnt = 113;
        while (cnt <= 120) {
          L1Skills l1skills = SkillsTable.get().getTemplate(cnt);
          skill_name = l1skills.getName();
          skill_id = l1skills.getSkillId();
          CharSkillReading.get().spellMastery(object_id, skill_id, skill_name, 0, 0);
          cnt++;
        } 
      } else if (pc.isKnight()) {
        pc.sendPackets((ServerBasePacket)new S_AddSkill(pc, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
              0, 0, 0, 0, 0, 0));
        cnt = 1;
        while (cnt <= 8) {
          L1Skills l1skills = SkillsTable.get().getTemplate(cnt);
          skill_name = l1skills.getName();
          skill_id = l1skills.getSkillId();
          CharSkillReading.get().spellMastery(object_id, skill_id, skill_name, 0, 0);
          cnt++;
        } 
        cnt = 87;
        while (cnt <= 91) {
          L1Skills l1skills = SkillsTable.get().getTemplate(cnt);
          skill_name = l1skills.getName();
          skill_id = l1skills.getSkillId();
          CharSkillReading.get().spellMastery(object_id, skill_id, skill_name, 0, 0);
          cnt++;
        } 
      } else if (pc.isElf()) {
        pc.sendPackets((ServerBasePacket)new S_AddSkill(pc, 255, 255, 127, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 3, 
              255, 255, 255, 255, 0, 0, 0, 0, 0, 0));
        cnt = 1;
        while (cnt <= 48) {
          L1Skills l1skills = SkillsTable.get().getTemplate(cnt);
          skill_name = l1skills.getName();
          skill_id = l1skills.getSkillId();
          CharSkillReading.get().spellMastery(object_id, skill_id, skill_name, 0, 0);
          cnt++;
        } 
        cnt = 129;
        while (cnt <= 176) {
          L1Skills l1skills = SkillsTable.get().getTemplate(cnt);
          skill_name = l1skills.getName();
          skill_id = l1skills.getSkillId();
          CharSkillReading.get().spellMastery(object_id, skill_id, skill_name, 0, 0);
          cnt++;
        } 
      } else if (pc.isWizard()) {
        pc.sendPackets((ServerBasePacket)new S_AddSkill(pc, 255, 255, 127, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
        cnt = 1;
        while (cnt <= 80) {
          L1Skills l1skills = SkillsTable.get().getTemplate(cnt);
          skill_name = l1skills.getName();
          skill_id = l1skills.getSkillId();
          CharSkillReading.get().spellMastery(object_id, skill_id, skill_name, 0, 0);
          cnt++;
        } 
      } else if (pc.isDarkelf()) {
        pc.sendPackets((ServerBasePacket)new S_AddSkill(pc, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 127, 0, 0, 0, 0, 0, 0, 0, 
              0, 0, 0, 0, 0, 0, 0));
        cnt = 1;
        while (cnt <= 16) {
          L1Skills l1skills = SkillsTable.get().getTemplate(cnt);
          skill_name = l1skills.getName();
          skill_id = l1skills.getSkillId();
          CharSkillReading.get().spellMastery(object_id, skill_id, skill_name, 0, 0);
          cnt++;
        } 
        cnt = 97;
        while (cnt <= 111) {
          L1Skills l1skills = SkillsTable.get().getTemplate(cnt);
          skill_name = l1skills.getName();
          skill_id = l1skills.getSkillId();
          CharSkillReading.get().spellMastery(object_id, skill_id, skill_name, 0, 0);
          cnt++;
        } 
      } else if (pc.isDragonKnight()) {
        pc.sendPackets((ServerBasePacket)new S_AddSkill(pc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 
              255, 7, 0, 0, 0));
        cnt = 181;
        while (cnt <= 195) {
          L1Skills l1skills = SkillsTable.get().getTemplate(cnt);
          skill_name = l1skills.getName();
          skill_id = l1skills.getSkillId();
          CharSkillReading.get().spellMastery(object_id, skill_id, skill_name, 0, 0);
          cnt++;
        } 
      } else if (pc.isIllusionist()) {
        pc.sendPackets((ServerBasePacket)new S_AddSkill(pc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
              0, 0, 255, 255, 15));
        cnt = 201;
        while (cnt <= 220) {
          L1Skills l1skills = SkillsTable.get().getTemplate(cnt);
          skill_name = l1skills.getName();
          skill_id = l1skills.getSkillId();
          CharSkillReading.get().spellMastery(object_id, skill_id, skill_name, 0, 0);
          cnt++;
        } 
      } 
    } catch (Exception e) {
      _log.error("错误的GM指令格式: " + getClass().getSimpleName() + " 执行的GM:" + pc.getName());
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(261));
    } 
  }
}
